package com.qf.day5;

import javax.servlet.*;
import java.io.IOException;

/**
 * @date 2022/3/29
 * @desc
 */


public class Filter1Demo implements Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        //初始化方法
        System.out.println("filter1初始化好了------------------------");
    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        // 把请求拦截下来  进行一番操作  根据业务需求  决定 是否 放行

        System.out.println("filter1过滤前。。。。foFilter");

        request.setCharacterEncoding("utf-8");
        response.setContentType("text/html; charset=UTF-8");

        System.out.println("filter1放行");

        //放行
        chain.doFilter(request,response);


        System.out.println("filter1过滤后，请求回来 再次经过。。。。foFilter");
    }

    @Override
    public void destroy() {
        //销毁
        System.out.println("filter1销毁了-----------------");
    }
}
